package com.group3.controller.adminController;

import com.group3.pojo.receive.PunchReceive;
import com.group3.service.APunchService;
import com.group3.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * APunchController
 *
 * @author HY
 * 2021/06/07 16:35
 **/

@RestController
@Api(tags = "管理员接口")
@CrossOrigin
@RequestMapping(value = "/admin/punch")
public class APunchController {

    @Resource
    private APunchService aPunchService;

    @ApiOperation(value = "管理员上传打卡记录接口")
    @PostMapping(value = "/clock")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件流",required = true,
                    dataType = "MultipartFile")
    })
    public Result addClock(@RequestParam("file") MultipartFile file,
                           HttpServletRequest request) {

        //String token = request.getHeader("token");//获取token
        String token = "";
        return aPunchService.addClock(file, token);
    }

    @ApiOperation("管理员上传打卡记录模板接口")
    @PostMapping(value = "/template")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件流",required = true,
                    dataType = "MultipartFile")
    })
    public Result addTemplate(@RequestParam("file") MultipartFile file,
                              HttpServletRequest request) {

        String token = request.getHeader("token");//获取token
        return aPunchService.addTemplate(file, token);
    }

    @ApiOperation("管理员导出打卡记录接口")
    @GetMapping(value = "/file")
    public Result<String> GetClock() {

        return aPunchService.GetClock();
    }

    @ApiOperation("管理员导出打卡记录接口")
    @GetMapping(value = "")
    public Result<String> selectClock(
            PunchReceive punchReceive
    ) {

        return aPunchService.selectClock(punchReceive);
    }
}
